# 暴力枚举
class Solution:
    def findPeakElement(self, nums: List[int]) -> int:
        if len(nums) == 1:
            return 0
        if len(nums) == 2:
            if nums[0] > nums[1]:
                return 0
            else:
                return 1
        for i in range(1,len(nums)-1):
            if nums[i-1] < nums[i] and nums[i] > nums[i+1]:
                return i

        if max(nums) == nums[0]:
            return 0
        else:
            return len(nums) - 1

# 二分
class Solution:
    def findPeakElement(self, nums: List[int]) -> int:
        n = len(nums)
        l,r = -1,n-2

        while l+1 < r:
            mid = (l+r) // 2
            if nums[mid] > nums[mid+1]:
                r = mid
            else:
                l = mid
        return r
